/**
****************************************************************************************
 * @Author: luoweiyong fortwater969@163.com
 * @Version: 
 * @Date: 2024-06-09 21:12:26
 * @LastEditors: luoweiyong fortwater969@163.com
 * @LastEditTime: 2024-06-09 21:12:26
 * @FilePath: \code\Bsp\user\user_tim1.c
 * @Description: 
 * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
****************************************************************************************
*/
#include "stm8s.h"
#include "user_tim1.h"

/*********************内部变量************************/
static uint32_t gTimer1_Delay;

//******************************************************************************
//name:             user_tim1_init
//introduce:        定时器1初始化
//parameter:
//return:           none
//author:
//email:
//changetime:
//******************************************************************************
void user_tim1_init(uint16_t psc, uint16_t arr, uint8_t duty)
{
    TIM1_TimeBaseInit(psc, TIM1_COUNTERMODE_UP, arr, duty);
    TIM1_ARRPreloadConfig(ENABLE);
    TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
    TIM1_Cmd(ENABLE);
}

//******************************************************************************
//name:             user_tim1_decrement
//introduce:        定时器1减1
//parameter:
//return:           none
//author:
//email:
//changetime:
//******************************************************************************
void user_tim1_decrement(void)
{
    if(gTimer1_Delay != 0)
    {
        gTimer1_Delay--;
    }
}

/**
****************************************************************************************
 * @Author: luoweiyong fortwater969@163.com
 * @Description: 
 * @param {uint32_t} nTime
 * @return {*}
****************************************************************************************
*/
void user_tim1_delay_50us(uint32_t nTime)
{
    gTimer1_Delay = nTime;
    while (gTimer1_Delay != 0);
}
